package com.powerteam.handler;

import com.powerteam.exception.BusinessException;
import com.powerteam.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理程序
 *
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/01/08
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    private static final String CLASS_NAME = "GlobalExceptionHandler";

    @ResponseBody
    @ExceptionHandler(value = BusinessException.class)
    public Result exceptionHandler(BusinessException e) {

        log.error("{} 系统发生异常, 原因: {}", CLASS_NAME, e.getMessage());

        return new Result(false, e.getMessage().concat(",请联系管理员!"));
    }

}
